 //!@Author: DengLibin
 //!@Date: Create in 2024-01-21 10:58:38
 //!@Description: 数组
#[allow(dead_code)]
pub fn hello_arr(){

    // 创建一个数组，有大小和元素类型
    let mut  arr:[i32; 10] = [0; 10];
    //添加元素
    for i  in 0..10 {
        arr[i] = i as i32;
    }

    show_arr(&arr);

    //删除元素
    remove_arr(&mut arr, 7);
    show_arr(&arr);


    //查找
    let target = find_arr(&arr, 6);
    match target {
        Some(i) =>{
            println!("查找成功:{}", i);
        },None =>{
            println!("查找失败")
        }
    }

   
}

///@Author: DengLibin
///@Date: Create in 2024-01-21 11:08:46
///@Description: 删除数组中的指定位置的元素
/// 后面的元素一次往前移动
fn remove_arr(arr: &mut[i32], index: usize){
    for i in index..arr.len()-1 {
        arr[i] = arr[i+1];
    }
}

///@Author: DengLibin
///@Date: Create in 2024-01-21 11:14:24
///@Description:查找
fn find_arr(arr: &[i32], index: usize)->Option<i32> {
    if index < arr.len() {
        return Some(arr[index]);
    }
    return None;
}


///@Author: DengLibin
///@Date: Create in 2024-01-21 11:04:39
///@Description: 遍历数组
fn show_arr(arr: &[i32]){
    for i in arr {
        print!("{},", i);
    }
    println!();
}